// package-owner/owner-activity/index.js
import { UserInfoUpdateMixins, ActivityMixins, ActivityListMixins } from '../../../behaviors/page';
import { PACKAGE_OWNER_PAGE } from '../../../constants/route';
import { ACTIVITY_LIST_TABS, ACTIVITY_OWNER_VALUE } from '../../../constants/activity';
import { navTo, showLoading, hideLoading } from '../../../common/env';
import { getAdvocacyActivityList } from '../../../api/usr';

Page({
    mixins: [UserInfoUpdateMixins, ActivityMixins, ActivityListMixins],
    data: {
        activityList: [],
        tabsData: ACTIVITY_LIST_TABS,
        expandCount: 0, // 代言的品牌数
    },
    onLoad(options) {
        const { expandCount } = options;
        this.setData({
            expandCount,
            pageNo: 1,
            pageTime: new Date().getTime(),
        }, async () => {
            await this.getActivityListData(true);
        });
    },
    getActivityListData: async function (isReplace=false) {
        showLoading('加载中...');
        const { pageNo, pageSize, pageTime, activeIndex, activityList, userInfo } = this.data;
        let param = {
            pageNo,
            pageSize,
            ts: pageTime,
        };
        const isAll = activeIndex === 'all';
        if (isAll) {
            param = {
                ...param,
                isAll,
            };
        } else {
            param = {
                ...param,
                processStatus: ACTIVITY_LIST_TABS.filter(item => item.name === activeIndex)[0].value,
            };
        }
        const ownerInfo = {
            owner: ACTIVITY_OWNER_VALUE.spokesman,
            ownerName: userInfo.nickName,
            ownerPic: userInfo.pic,
            canManage: true,
        };
        const list = await getAdvocacyActivityList(param, ownerInfo);
        console.log('OwnerActivity => 获取的列表数据为：', list);
        this.setData({
            activityList: isReplace ? list : [...activityList, ...list],
        });
        hideLoading();
    },
    handleNavToEndorsement() {
        navTo(PACKAGE_OWNER_PAGE.ownerEndorsement);
    },
})
